package org.summerframework.web.exception.resolver;

import org.summerframework.core.base.result.ResultCode;
import org.summerframework.core.base.result.ResultDTO;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 石超
 * @version v1.0.0
 */
public interface ExceptionResolveHandler {
    /**
     * 解析返回的resultCode
     *
     * @param request  请求
     * @param response 响应
     * @param handler  handler
     * @param ex       异常
     * @return 返回编码
     */
    ResultCode resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);

    /**
     * 支持的exception
     *
     * @param ex 异常
     * @return 是否支持
     */
    boolean supper(Exception ex);

    /**
     * 异常后, 返回的界面
     *
     * @param request   上下文
     * @param resultDTO 返回值
     * @param isHtml    当前是否是html
     * @param e         异常
     * @return 界面, null时不做处理
     */
    default ModelAndView determineModelAndView(HttpServletRequest request, ResultDTO resultDTO, boolean isHtml, Exception e) {
        return null;
    }
}
